package cloud.daodao.storm.security.controller;

import cloud.daodao.storm.common.security.model.rsa.*;
import cloud.daodao.storm.security.service.RsaService;
import cloud.daodao.storm.common.security.api.RsaApi;
import cloud.daodao.storm.common.model.Request;
import cloud.daodao.storm.common.model.Response;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DaoDao
 */
@RestController
public class RsaController implements RsaApi {

    @Resource
    private RsaService rsaService;

    @Override
    public Response<RsaCipherData> rsaEncrypt(@RequestBody @Valid Request<RsaCipherParam> request) {
        RsaCipherData data = rsaService.rsaEncrypt(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<RsaCipherData> rsaDecrypt(@RequestBody @Valid Request<RsaCipherParam> request) {
        RsaCipherData data = rsaService.rsaDecrypt(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<RsaSignData> rsaSign(@RequestBody @Valid Request<RsaSignParam> request) {
        RsaSignData data = rsaService.rsaSign(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<RsaVerifyData> rsaVerify(@RequestBody @Valid Request<RsaVerifyParam> request) {
        RsaVerifyData data = rsaService.rsaVerify(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<RsaKeyData> rsaGenerateKey(@RequestBody @Valid Request<RsaKeyParam> request) {
        RsaKeyData data = rsaService.rsaGenerateKey(request.getParam());
        return new Response<>(data);
    }

    @Override
    public Response<RsaKeyData> rsaExtractPublicKey(Request<RsaPrivateKeyParam> request) {
        RsaKeyData data = rsaService.rsaExtractPublicKey(request.getParam());
        return new Response<>(data);
    }

}
